package com.xmut.mall.store.controller;

import java.util.Arrays;
import java.util.Map;

import com.xmut.mall.store.annotation.CheckJwt;
import com.xmut.mall.store.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.store.entity.StoreLogisticsEntity;
import com.xmut.mall.store.service.StoreLogisticsService;
import com.xmut.mall.store.utils.PageUtils;
import com.xmut.mall.store.utils.R;


/**
 * @author 1912120131suntingxing
 * @email 1192081604@qq.com
 * @date 2023-02-13 03:45:06
 */
@RestController
@RequestMapping("store/storelogistics")
public class StoreLogisticsController {
    @Autowired
    private StoreLogisticsService storeLogisticsService;

    /**
     * 取消选择物流公司
     * @param id
     * @param storeId
     * @return
     */
    @CheckJwt
    @DeleteMapping("/cancelStoreLogistics/{id}/{storeId}")
    public RespBean cancelStoreLogistics(@PathVariable("id") Long id, @PathVariable("storeId") Long storeId) {
        return storeLogisticsService.cancelStoreLogistics(id,storeId);
    }

    /**
     * 添加 店铺-物流公司 关联
     *
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/addStoreLogistics")
    public RespBean addStoreLogistics(@RequestBody Map<String, Object> param) {
        return storeLogisticsService.addStoreLogistics(param);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = storeLogisticsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        StoreLogisticsEntity storeLogistics = storeLogisticsService.getById(id);

        return R.ok().put("storeLogistics", storeLogistics);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StoreLogisticsEntity storeLogistics) {
        storeLogisticsService.save(storeLogistics);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StoreLogisticsEntity storeLogistics) {
        storeLogisticsService.updateById(storeLogistics);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        storeLogisticsService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
